<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script src="../js/vue.js"></script>
<!--父组件-->
<div id="app">
  <cpn @btnclick="cpnclick"></cpn>
</div>
<!--子组件-->
<template id="cpn">
  <div>
    <button v-for="item in list" @click="btnclick(item)">{{item.name}}</button>
  </div>
</template>
<script>
  const  cpn={
    template:"#cpn",
    data(){
      return{
        list:[
          {id:'aaa',name:'热门推荐'},
          {id:'bbb',name:'电子产品'},
          {id:'ccc',name:'家用电器'}
        ]
      }
    },
    methods:{
      //发送事件：自定义事件
      btnclick(item){
        this.$emit('btnclick',item)

      }
    }
  }
    const app = new Vue({
        el:'#app',
        data:{
            message:'hello vue',
        },
      methods: {
        cpnclick(item){
          console.log(item)
        }
      },
      components:{
          cpn
      }

    })
</script>

</body>
</html>